package com.byCreation.t_globe;


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

import net.londatiga.android.TwitterApp;

import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import FileIO.ReadWrite;
import FileIO.SaveImage;
import Myclass.ConnectInternet;
import Parser.SendToBD;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.byCreation.Control.Control;
import com.byCreation.t_globe.R;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.BaseRequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.SessionStore;
import com.facebook.android.Facebook.DialogListener;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;






public class LoginActivity extends Activity implements OnClickListener{

	
	
	
	
	
	
	private LinearLayout txt_next,txt_register;
	private ConnectInternet connect=new ConnectInternet(LoginActivity.this);
	


	//========================Facebook Share============================
		private Facebook mFacebook;
		private ProgressDialog mProgress;
		private Handler mRunOnUi = new Handler();
		private static final String[] PERMISSIONS = new String[] {"publish_stream", "read_stream", "offline_access"};
		private String Faceboook_Id="1396426917291657"; 
//				
	
		
		
		
		// ===============GoogleAnalytics==============
					private GoogleAnalytics mGaInstance;
					private Tracker mGaTracker;
					// =============================================
		// ===================================googleAnalytics=============================
				@Override
				public void onStart() {
					super.onStart();
					// The rest of your onStart() code.
					EasyTracker.getInstance().activityStart(this); // Add this method.
					mGaTracker.sendView("LoginScreen");

				}

				@Override
				public void onStop() {
					super.onStop();
					// The rest of your onStop() code.
					EasyTracker.getInstance().activityStop(this); // Add this method.

				}

				// ================================================================================
	
	@SuppressWarnings("static-access")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.activity_login);
		
		// =============================GoogleAnalytics=========================
		mGaInstance = GoogleAnalytics.getInstance(this);
		mGaTracker = mGaInstance.getTracker(Control.IDGoogleanalytics);
		
		
//		Login_path="/mnt/sdcard/Android/data/"+LoginActivity.this.getPackageName()+"/Login_Tglobe.txt";
//		Login_Dir="/mnt/sdcard/Android/data/"+LoginActivity.this.getPackageName();
		
		
		 try {
	            PackageInfo info = getPackageManager().getPackageInfo("com.byCreation.t_globe",PackageManager.GET_SIGNATURES);
	            for (Signature signature : info.signatures) {
	                MessageDigest md = MessageDigest.getInstance("SHA");
	                md.update(signature.toByteArray());
	                Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
	                }
	        } catch (NameNotFoundException e) {

	        } catch (NoSuchAlgorithmException e) {

	        }
		
		
		
		SocialInit();
		setView();
		
		
		
//		if(Control.Loginstatus)
//		{
//			startActivity(new Intent(LoginActivity.this, MainActivity.class));
//			overridePendingTransition(R.anim.blur_fade_in, R.anim.blur_fade_out);
//		}
		
		
		Chk_Login();
		
	}

	
	
	private void Chk_Login()
	{
		
		SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	
		
		Log.e("tglobe",sharedpreferences.getString("Username", ""));
		Log.e("tglobe",sharedpreferences.getString("Password", ""));

		Username=sharedpreferences.getString("Username", "");
		Password=sharedpreferences.getString("Password", "");
		
		
		try{
			if(!sharedpreferences.getString("Username", "").equals(""))
			{
				
				if(new ConnectInternet(this).checkInternetConnection())
				new Login().execute();
			}
			
		}catch (Exception ex){    };
	}
	
	
	private void setView()
	{
		txt_next=(LinearLayout)findViewById(R.id.txt_next);
		txt_next.setOnClickListener(this);
		
		txt_register=(LinearLayout)findViewById(R.id.txt_register);
		txt_register.setOnClickListener(this);
		
		
		ImageView img_tglobe_login=(ImageView)findViewById(R.id.img_tglobe_login);
		img_tglobe_login.setOnClickListener(this);
		
		ImageView img_facebook =(ImageView)findViewById(R.id.img_facebook);
		img_facebook.setOnClickListener(this);
		
		
		
		
		
	}
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
	/////Mainmenu
			
			
			
		super.onRestart();
	}


	private void SocialInit() {
		// TODO Auto-generated method stub
		//===============Facebook========
		  mProgress		= new ProgressDialog(this);
	      mFacebook		= new Facebook(Faceboook_Id);
	      SessionStore.restore(mFacebook, this);
	        if (mFacebook.isSessionValid()) {
				String name = SessionStore.getName(this);
				name		= (name.equals("")) ? "Unknown" : name;
			}
	        
	        
	   
			
	        
	}
	
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.txt_next)
		{
			finish();
			startActivity(new Intent(LoginActivity.this, MainActivity.class));
			overridePendingTransition(R.anim.blur_fade_in, R.anim.blur_fade_out);
		}
		
		if(v.getId()==R.id.img_tglobe_login)
		{
			ShowDialog_Login();
		}
		
		if(v.getId()==R.id.txt_register)
		{
			ShowDialog_Register();
		}
		
		if(v.getId()==R.id.img_facebook)
		{
			 mFacebook.authorize(LoginActivity.this, PERMISSIONS, -1, new FbLoginDialogListener());
        	
		}
	}

	

	
	
	
	//Dialog Login
	private String Username="",Password="",Email="",facebookid="";
	public void ShowDialog_Login()
	{
		 Username="";Password="";Email="";facebookid="";
		final Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
		//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
		//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
		dialog.setContentView(R.layout.dialog_login);
        dialog.setCancelable(true);
        dialog.show();
        
        final AutoCompleteTextView edt_username=(AutoCompleteTextView)dialog.findViewById(R.id.edt_username);
        final AutoCompleteTextView edt_pass=(AutoCompleteTextView)dialog.findViewById(R.id.edt_pass);
        
        edt_username.setOnKeyListener(new OnKeyListener() {
          
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
		                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
		                  // Perform action on key press
		                  //Toast.makeText(LoginActivity.this, edt_username.getText(), Toast.LENGTH_SHORT).show();
		                  edt_pass.requestFocus();
		                  return true;
		                }
		                return false;
			}
        });
        
        
        
        
        edt_pass.setOnKeyListener(new OnKeyListener() {
            
  			@Override
  			public boolean onKey(View v, int keyCode, KeyEvent event) {
  				 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
  		                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
  		                  // Perform action on key press
  		                 // Toast.makeText(.this, edt_pass.getText(), Toast.LENGTH_SHORT).show();	
  		                  Username=edt_username.getText().toString();
  		                  Password=edt_pass.getText().toString();
  		                
  		                  dialog.dismiss();
  		                 
  		                  	if(connect.checkInternetConnection())
  		                  	{
  		                  		new Login().execute();
  		                  	}    
  		                  	
  		                  	
  		                  return true;
  		                }
  				 
  		                return false;
  			}
          });
          
        
        dialog.findViewById(R.id.img_login).setOnClickListener(new OnClickListener() {  
            public void onClick(View v){
            	
           
            Username=edt_username.getText().toString();
              Password=edt_pass.getText().toString();
              
              if(connect.checkInternetConnection())
              	{
            	  new Login().execute();
            	  //Toast.makeText(LoginActivity.this, Username+" "+Password, 900).show();
              	}
            dialog.dismiss(); 
            
            
        }});
        
        
	}
	public void ShowDialog_Register()
	{
		Username="";Password="";Email="";facebookid="";
		final Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
		//dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
		//dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
		dialog.setContentView(R.layout.dialog_register);
        dialog.setCancelable(true);
        dialog.show();
        
        final AutoCompleteTextView edt_username=(AutoCompleteTextView)dialog.findViewById(R.id.edt_username);
        final AutoCompleteTextView edt_pass=(AutoCompleteTextView)dialog.findViewById(R.id.edt_pass);
        final AutoCompleteTextView edit_email=(AutoCompleteTextView)dialog.findViewById(R.id.edit_email);
        
        edt_username.setOnKeyListener(new OnKeyListener() {
          
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
		                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
		                  // Perform action on key press
		                  Toast.makeText(LoginActivity.this, edt_username.getText(), Toast.LENGTH_SHORT).show();
		                  edt_pass.requestFocus();
		                  return true;
		                }
		                return false;
			}
        });
        
        
        
        
        edt_pass.setOnKeyListener(new OnKeyListener() {
            
  			@Override
  			public boolean onKey(View v, int keyCode, KeyEvent event) {
  				 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
  		                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
  		                  // Perform action on key press
  		                 // Toast.makeText(.this, edt_pass.getText(), Toast.LENGTH_SHORT).show();	
  		               
  					      edit_email.requestFocus();
  		                  	
  		                  return true;
  		                }
  				 
  		                return false;
  			}
          });
          
        
        
        
        edit_email.setOnKeyListener(new OnKeyListener() {
            
  			@Override
  			public boolean onKey(View v, int keyCode, KeyEvent event) {
  				 if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
		                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
		                  // Perform action on key press
		                 // Toast.makeText(.this, edt_pass.getText(), Toast.LENGTH_SHORT).show();	
		                  Username=edt_username.getText().toString();
		                  Password=edt_pass.getText().toString();
		                
		                  dialog.dismiss();
		                 
		                  	if(connect.checkInternetConnection())
		                  	{
		                  		new Register().execute();
		                  	}    
		                  	
		                  	
		                  return true;
		                }
				 
		                return false;
			}
       });
       
     
          
        
        
        
        dialog.findViewById(R.id.img_register).setOnClickListener(new OnClickListener() {  
            public void onClick(View v){
            	
           
              Username=edt_username.getText().toString();
              Password=edt_pass.getText().toString();
              Email=edit_email.getText().toString();
              if(connect.checkInternetConnection())
              	{
            	 // new Login().execute();
            		new Register().execute();
            	  // Toast.makeText(LoginActivity.this, Username+" "+Password+" "+Email, 900).show();
              	}
            dialog.dismiss(); 
            
            
        }});
        
        
	}
	
	private ProgressDialog mProgressDialog;
	private boolean Login_ok=false;
	private String desc="";
	
	class Register extends AsyncTask<Object, Integer, Object> {

		@SuppressWarnings("null")
		@Override
		protected Object doInBackground(Object... params) {
		try {
			 ArrayList<String> arrayList_parametor=new ArrayList<String>();
			 ArrayList<String> arrayList_value=new ArrayList<String>();
			
			 arrayList_parametor.add("username");
			 arrayList_value.add(Username);
				
			 arrayList_parametor.add("password");
			 arrayList_value.add(Password);
			 
			 arrayList_parametor.add("email");
			 arrayList_value.add(Email);
			 
			 arrayList_parametor.add("facebookid");
			 arrayList_value.add(facebookid);
			 
			 
			 arrayList_parametor.add("img_profile");
			 arrayList_value.add("http://graph.facebook.com/"+facebookid+"/picture?type=square");
			

			 
			 SendToBD sd=new SendToBD(LoginActivity.this);
			 String respone=sd.send(
						Control.user, 
						Control.pass, 
						Control.API_Register,
						arrayList_parametor,
						arrayList_value);
				
				JSONObject jsonObj;
				jsonObj = new JSONObject(respone);
				Log.e("tg","result="+jsonObj.getString("result"));
			    
				
				if(jsonObj.getString("result").equals("success"))
				Login_ok=true;
				desc=jsonObj.getString("desc");
				
				Control.UserPassword=Password;
			    
			 
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
			
				 
			return null;
		}

		@Override
		protected void onPreExecute() {

			   mProgressDialog = new ProgressDialog(LoginActivity.this);
		        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
		        mProgressDialog.setMessage("Loading......");                       
		    	mProgressDialog.setCancelable(true);

			
			if(mProgressDialog!=null)
				mProgressDialog.show();

			
			
			
			
			super.onPreExecute();
		}

		@Override
		public void onProgressUpdate(Integer... progress) {

			Log.e("star", "progressupdate");
			
			
		}

		
		
		
		
		
		@Override
		protected void onPostExecute(Object result) {
			if(Login_ok)
			{
				Login_ok=false;
				
				SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	
				Editor editor = sharedpreferences.edit();
				editor.putString("Username", Username);
				editor.putString("Password", Password);
				editor.commit();
				
				finish();
				Control.UserPassword=Password;
				startActivity(new Intent(LoginActivity.this, MainActivity.class));
				overridePendingTransition(R.anim.blur_fade_in, R.anim.blur_fade_out);
			     Control.Loginstatus=true;
			}
			else
			{
				if(desc.equals("register already"))
				{
					Control.Loginstatus=false;
					ShowDialog_Register();
				}
				else
				{
					Login_ok=false;
					
					SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	
					Editor editor = sharedpreferences.edit();
					editor.putString("Username", Username);
					editor.putString("Password", Password);

					editor.commit();
					
					finish();
					Control.UserPassword=Password;

					startActivity(new Intent(LoginActivity.this, MainActivity.class));
					overridePendingTransition(R.anim.blur_fade_in, R.anim.blur_fade_out);
				   Control.Loginstatus=true;
					
				   
				   Log.e("Username", Username);
				   Log.e("Password", Password);

				   
				}
				
			}
			
			Toast.makeText(LoginActivity.this, desc, 900).show();
			
			
			
			 if(mProgressDialog != null)
		            mProgressDialog.dismiss();
			
			
		
			 
		}

		
	}
	

	class Login extends AsyncTask<Object, Integer, Object> {

		@SuppressWarnings("null")
		@Override
		protected Object doInBackground(Object... params) {
		
			String respone="";
			try {
			 ArrayList<String> arrayList_parametor=new ArrayList<String>();
			 ArrayList<String> arrayList_value=new ArrayList<String>();
			
			 arrayList_parametor.add("username");
			 arrayList_value.add(Username);
				
			 arrayList_parametor.add("password");
			 arrayList_value.add(Password);
	
			 
			
			 
			 SendToBD sd=new SendToBD(LoginActivity.this);
			 respone=sd.send(
						Control.user, 
						Control.pass, 
						Control.API_Login,
						arrayList_parametor,
						arrayList_value);
				
				JSONObject jsonObj;
				jsonObj = new JSONObject(respone);
				
				
				Log.e("tg","result="+jsonObj.getString("result"));
				if(jsonObj.getString("result").equals("success"))
				Login_ok=true;
				
				String desc2 = null;
				try{desc2=jsonObj.getString("desc");}catch(Exception ex){};
				
				
				desc=jsonObj.getString("result")+desc2;
				
				
				
				
				//================
				JSONArray jarray_account =jsonObj.getJSONArray("account");
			    JSONObject jsonObj_player=jarray_account.getJSONObject(0);
			    
			    
			    Log.e("tg",jsonObj_player.getString("username"));
			    Log.e("tg",jsonObj_player.getString("email"));
			    Log.e("tg",jsonObj_player.getString("date_regist"));
			    Log.e("tg","url:"+jsonObj_player.getString("url"));
			    Control.Img_profile=jsonObj_player.getString("url");
			    
			    try {

				    SaveImage.storeImage(SaveImage.getCroppedBitmap(SaveImage.getBitmapFromURL(jsonObj_player.getString("url"))),LoginActivity.this);

				} catch (Exception e) {
					
					// TODO: handle exception
				e.printStackTrace();
				}
			    
			 
			} catch (JSONException e) {
				e.printStackTrace();
				desc=respone;
			}
			
				
		
		
		
			
				 
			return null;
		}

		@Override
		protected void onPreExecute() {

			
			
			
			
			
			
			    mProgressDialog = new ProgressDialog(LoginActivity.this);
		        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
		        mProgressDialog.setMessage("Login......");                       
		    	mProgressDialog.setCancelable(true);

			
			if(mProgressDialog!=null)
				mProgressDialog.show();

			
			
			
			
			super.onPreExecute();
		}

		@Override
		public void onProgressUpdate(Integer... progress) {

			Log.e("star", "progressupdate");
			
			
		}

		
		
		
		
		
		@Override
		protected void onPostExecute(Object result) {
			if(Login_ok)
			{
				Login_ok=false;
				
				
				Control.UserName=Username;
				
				finish();
				Control.UserPassword=Password;

				startActivity(new Intent(LoginActivity.this, MainActivity.class));
				overridePendingTransition(R.anim.blur_fade_in, R.anim.blur_fade_out);
				
				Control.Loginstatus=true;
				
				
				SharedPreferences sharedpreferences = getSharedPreferences("Tglobe", Context.MODE_PRIVATE);	
				Editor editor = sharedpreferences.edit();
				editor.putString("Username", Username);
				editor.putString("Password", Password);

				editor.commit();
				
				
				
			}
			else
			{
				Control.Loginstatus=false;
				ShowDialog_Login();
				Toast.makeText(LoginActivity.this, desc, 2000).show();
			}
			
			
			
			
			
			 if(mProgressDialog != null)
		            mProgressDialog.dismiss();
			
			
		
			 
		}

		
	}
	
	
	
	
	//=========Facebook
	//=========================Post Facebook============================
	private void postToFacebook(String review) {	
		mProgress.setMessage("Posting ...");
		mProgress.show();
		
		AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);
		
		Bundle params = new Bundle();
			
		params.putString("message","" );
		params.putString("name", "");
		params.putString("caption", "");
		params.putString("link", "http://www.r-siam.com/");
		//params.putString("description","ฉันกำลังฟังเพลง "+nowplaying+" จาก 88.5 สบายดีเรดิโอ");
		params.putString("picture", "http://cloud.horomate.com/rsiam/img/88.5.png");
		
		mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());
	}
	
	private final class WallPostListener extends BaseRequestListener {
	 public void onComplete(final String response) {
	 	mRunOnUi.post(new Runnable() {
	 		@Override
	 		public void run() {
	 			mProgress.cancel();        			
	 			Toast.makeText(LoginActivity.this, "Facebook Post", Toast.LENGTH_SHORT).show();
	 			//finish();
	 		}
	 	});
	 }
	}
	private final class FbLoginDialogListener implements DialogListener {
	     public void onComplete(Bundle values) {
	         SessionStore.save(mFacebook,LoginActivity.this);
	         //postToFacebook("");
	         //AsyncFacebookRunner myAsyncRunner = new AsyncFacebookRunner(mFacebook);
	        
	         
	        // myAsyncRunner.request("me", new meRequestListener());
			if(new ConnectInternet(LoginActivity.this).checkInternetConnection())	 
	        new getFbName().execute();
	     }
	
	     public void onFacebookError(FacebookError error) {
	        Toast.makeText(LoginActivity.this, "Facebook connection failed"+error, Toast.LENGTH_SHORT).show();
	        
	      
	     }
	     
	     public void onError(DialogError error) {
	     	Toast.makeText(LoginActivity.this, "Facebook connection failed"+error, Toast.LENGTH_SHORT).show(); 
	     	
	     	
	     }
	
	     public void onCancel() {
	     	
	     }
	 }
	 
	
	class getFbName extends AsyncTask<Object, Integer, Object> {

		@SuppressWarnings("null")
		@Override
		protected Object doInBackground(Object... params) {
		
			String name = "",first_name="",id="";
	        
			String me;
			try {
				me = mFacebook.request("me");
			
        	Log.e("tglobe", "facebook me :"+me);
        	JSONObject jsonObj =new JSONObject(me);
        	name = jsonObj.getString("name");
        	first_name = jsonObj.getString("first_name");
        	id= jsonObj.getString("id");
        	
        	
        	
        	} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	
        	
        	Log.e("tglobe", "facebook Name :"+name);
        	Log.e("tglobe", "facebook first_name :"+first_name);
        	Log.e("tglobe", "facebook id :"+id);
        	
        	
        	
        	Username=name;
        	Password=id;
        	Email=id+"@facebook.com";
        	facebookid=id;
				 
			return null;
		}

		@Override
		protected void onPreExecute() {

			   mProgressDialog = new ProgressDialog(LoginActivity.this);
		        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
		        mProgressDialog.setMessage("Loading......");                       
		    	mProgressDialog.setCancelable(true);

			
			if(mProgressDialog!=null)
				mProgressDialog.show();

			
			
			
			
			super.onPreExecute();
		}

		@Override
		public void onProgressUpdate(Integer... progress) {

			Log.e("star", "progressupdate");
			
			
		}

		
		
		
		
		
		@Override
		protected void onPostExecute(Object result) {
			
			
			 if(mProgressDialog != null)
		            mProgressDialog.dismiss();
			
				if(new ConnectInternet(LoginActivity.this).checkInternetConnection())
			new Register().execute();
		
			 
		}

		
	}

	
		
		private void fbLogout() {
			mProgress.setMessage("Facebook Logout");
			mProgress.show();
				
			new Thread() {
				@Override
				public void run() {
					SessionStore.clear(LoginActivity.this);
			        	   
					int what = 1;
						
			        try {
			        	mFacebook.logout(LoginActivity.this);
			        		 
			        	what = 0;
			        } catch (Exception ex) {
			        	ex.printStackTrace();
			        }
			        	
			        mHandler.sendMessage(mHandler.obtainMessage(what));
				}
			}.start();
		}
		
		private Handler mFbHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				mProgress.dismiss();
				
				if (msg.what == 0) {
					String username = (String) msg.obj;
			        username = (username.equals("")) ? "No Name" : username;
			            
			        SessionStore.saveName(username, LoginActivity.this);
			        
			       
			       
				} else {
					
				}
			}
		};
		
		private Handler mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				mProgress.dismiss();
				
				if (msg.what == 1) {
					
				} else {
				
		        	   
					
				}
			}
		};
	
	
		public class meRequestListener implements RequestListener {

		    
			@Override
			public void onComplete(String response) {
				// TODO Auto-generated method stub
				Log.e("response","response="+ response);
			}
			@Override
			public void onIOException(IOException e) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onFileNotFoundException(FileNotFoundException e) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onMalformedURLException(MalformedURLException e) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onFacebookError(FacebookError e) {
				// TODO Auto-generated method stub
				
			}

		    //You also have to override all the other methods
		}
	
}
